package com.ytjj.qmyx.supplychain.service;

import com.ytjj.qmyx.supplychain.mapper.ExpressDicMapper;
import com.ytjj.qmyx.supplychain.mapper.entity.YxExpressDic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ExpressDicService {
    @Resource
    private ExpressDicMapper expressDicMapper;

    public List<YxExpressDic> queryExpressDicListByExpressValue(String expressValue) {
        Example example = new Example(YxExpressDic.class);
        example.createCriteria().andEqualTo("expressValue", expressValue);
        List<YxExpressDic> list = expressDicMapper.selectByExample(example);
        return list;
    }

    public List<YxExpressDic> queryExpressDicListByExpressValues(List<String> expressValues) {
        Example example = new Example(YxExpressDic.class);
        example.createCriteria().andIn("expressValue",expressValues);
        List<YxExpressDic> list = expressDicMapper.selectByExample(example);
        return list;
    }

    public List<YxExpressDic> queryExpressDicListByExpressKey(String expressKey) {
        Example example = new Example(YxExpressDic.class);
        example.createCriteria().andEqualTo("expressKey", expressKey);
        List<YxExpressDic> list = expressDicMapper.selectByExample(example);
        return list;
    }

    public List<YxExpressDic> getExpressList() {
        List<YxExpressDic> yxExpressDicList = expressDicMapper.selectAll();
        return yxExpressDicList.stream()
                .sorted(Comparator.comparing(YxExpressDic::getId))
                .collect(Collectors.toList());
    }
}
